Test Series - Data Structure

Test Number 23/115

Q: How many stacks are required for applying evaluation of infix expression algorithm?
A. one
B. two
C. three
D. four
Solution: Two stacks are required for evaluation of infix expression – one for operands and one for operators.
Q: How many passes does the evaluation of infix expression algorithm makes through the input?
A. One
B. Two
C. Three
D. Four
Solution: Evaluation of infix expression algorithm is linear and makes only one pass through the input.
Q: Identify the infix expression from the list of options given below.
A. a/b+(c-d)
B. abc*+d+ab+cd+*ce-f-
C. ab-c-
D. +ab
Solution: a/b+(c-d) is an infix expression since the operators are placed in between the operands.
Q: Which of the following statement is incorrect with respect to evaluation of infix expression algorithm?
A. Operand is pushed on to the stack
B. If the precedence of operator is higher, pop two operands and evaluate
C. If the precedence of operator is lower, pop two operands and evaluate
D. The result is pushed on to the operand stack
Solution: If the precedence of the operator is higher than the stack operator, then it is pushed on to the stack operator.
Q: Evaluate the following statement using infix evaluation algorithm and choose the correct answer. 1+2*3-2
A. 3
B. 6
C. 5
D. 4
Solution: According to precedence of operators, * is evaluated first. + and – have equal priorities. Hence, 1+6-2= 5.
Q: Evaluation of infix expression is done based on precedence of operators.
A. True
B. False
C. none
D. blank
Solution: During evaluation of infix expression, the operators with higher precedence are evaluated first, followed by operators with lower precedence.
Q: Of the following choices, which operator has the lowest precedence?
A. ^
B. +
C. /
D. #
Solution:  The operator with the lowest precedence is #, preceded by +, / and then ^.
Q: The system throws an error if parentheses are encountered in an infix expression evaluation algorithm.
A. True
B. False
C. none
D. blank
Solution: The algorithm holds good for infix expression with parentheses. The system does not throw error.
Q: Evaluate the following and choose the correct answer.
a/b+c*d where a=4, b=2, c=2, d=1.
A. 1
B. 4
C. 5
D. 2
Solution: * and / have higher priority. Hence, they are evaluated first. Then, + is evaluated. Hence, 2+2=4.
Q: Evaluate the following statement using infix evaluation algorithm and choose the correct answer. 4*2+3-5/5
A. 10
B. 11
C. 16
D. 12
Solution: 4*2 and 5/5 are evaluated first and then, 8+3-1 is evaluated and the result is obtained as 10.

You Have Score    /10